package com.example.plusz.controller;

import com.example.plusz.entity.Student;
import com.example.plusz.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName StudentController
 * @Description TODO
 * @Author HP
 * @Date 16:18 2022/7/21
 * @Version 1.0
 **/
@RestController
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StudentService studentService;

    //查询所有学生
    @RequestMapping("/findAll")
    public List<Student> findAllStudent() {

        return studentService.list(null);
    }

    //通过id查询学生
    @RequestMapping("/findById")
    public Student findStudentById(@RequestParam Long id) {

        return studentService.getById(id);
    }

    //添加学生信息
    @RequestMapping("/save")
    public boolean saveStudent(@RequestBody Student student) {

        return studentService.save(student);
    }

    //修改学生信息
    @RequestMapping("/update")
    public boolean updateStudentById(@RequestBody Student student) {

        return studentService.updateById(student);
    }

    //根据id删除学生信息
    @RequestMapping("/removeById")
    public boolean removeStudentById(@RequestParam Long id) {

        return studentService.removeById(id);
    }

    //批量删除学生信息
    @RequestMapping("/removeByIds")
    public boolean removeStudentByIds(@RequestBody List<Integer> ids) {

        return studentService.removeByIds(ids);
    }
}
